package com.oocl.ita.handler;

import java.util.Collections;
import java.util.List;
import java.util.Vector;

import javax.swing.JList;
import javax.swing.ListCellRenderer;

import com.oocl.ita.qqclientt.QQClient;
import com.oocl.ita.sakura.client.Client;
import com.oocl.ita.sakura.protocol.Protocol;
import com.oocl.ita.ui.ChatFrame;

public class SynHandler implements IHandler {
	public void handle(Protocol protocol) {
		/*
		 * 获取List，更新JList（accountlist），开始设置UI
		 */

		// debug
		System.out.println("SynHandler : "  + QQClient.getClient());

		// 1. 获取List<Client>
		System.out.println("SynHandler : "  + QQClient.getClient() + " " + protocol);
		List<Client> listClient = (List<Client>) protocol.getParams().get("list");

		// 2. 更新JList，显示更新的联系人列表
		updateJList(listClient);
	}

	public void updateJList(List<Client> listClient) { // 更新JList
		JList contactJList = ChatFrame.getContactJList(); // 静态
		if (listClient != null) {
			if (contactJList != null) {
				contactJList.removeAll();
				contactJList.setListData(new Vector<Client>(listClient));
				contactJList.repaint();
			} else {
				System.out.println("Warning : "  + QQClient.getClient() + " contactJList is null");
				throw new NullPointerException();				
			}
		} else {
			System.out.println("SynHandler : "  + QQClient.getClient() + " listClient is null");
		}
	}

}
